<template>
  <a-modal title="平均耗时详情" :visible="visible" :width="1000" @cancel="closeModal" :bodyStyle="{ maxHeight: '72vh',overflow: 'auto' }">
    <template slot="footer">
      <a-button @click="closeModal">关闭</a-button>
    </template>
    <a-card :bordered="false">
      <a-table 
        ref="table" 
        bordered size="middle" 
        rowKey="id" 
        :columns="columns" 
        :dataSource="dataSource"
        :pagination="false"
      >
        <div slot="taskName" slot-scope="text">
          <j-ellipsis :value="text" />
        </div>
      </a-table>
    </a-card>
  </a-modal>
</template>

<script>
import { getAction } from '@/api/manage';
import JEllipsis from '@/components/jeecg/JEllipsis'
import moment from 'dayjs'
export default {
  name: 'approvalTimeModal',
  components: { JEllipsis },
  data() {
    return {
      dataSource: [],
      loading: false,
      columns: [
        {
          title: '审批节点名称',
          dataIndex: 'taskName',
          scopedSlots: { customRender: 'taskName' },
          align: 'center',
          width: '25%'
        },
        {
          title: '平均耗时',
          dataIndex: 'avgDurationFormat',
          align: 'center',
          width: '25%'
        },
      ],
      visible: false,
    }
  },
  methods: {
    showModal(record,key,time) {
      this.visible = true
      let startTime = `${moment(time[0]).format('YYYY-MM')}-01`
      let endTime = `${moment(time[1]).endOf('month').format('YYYY-MM-DD')}`
      this[`${key}Init`](record,startTime,endTime)
    },
    userInit(record,startTime,endTime){
      const params = {
        username: record.username,
        processKey: record.processKey,
        startTime,
        endTime
      }
      getAction('/api/erpmng/sys/board/avgDuaPerUserTask',params).then(res => {
        if(res.success){
          this.dataSource = res.result || []
        }
      })
    },
    departInit(record,startTime,endTime){
      const params = {
        departId: record.departId,
        processKey: record.processKey,
        startTime,
        endTime
      }
      getAction('/api/erpmng/sys/departProcessRank/deptDurationPerTask',params).then(res => {
        if(res.success){
          this.dataSource = res.result || []
        }
      })
    },
    closeModal() {
      this.visible = false
      this.dataSource = []
    }
  }
}
</script>
<style scoped></style>